import {
  saleRestrictOptions,
  packageLayersOptions,
  skuOriginalOptions
} from '@/pages/commodity/modules/constants/skuInfoModule/skuOptionsList';
export const singleAddSkuInfoColumnsFn = (data) => {
  let {
    handleChooseMainUnit,
    handleChooseOriginalPlace
  } = data;
  let columns = [
    {
      title: 'SKU编码',
      key: 'skuNo',
      align: 'center',
    },
    {
      title: '销售属性',
      key: 'skuName',
      align: 'center',
    },
    {
      title: '加价类型',
      key: 'addPriceType',
      align: 'center',
      formatter: (row, columns, cellValue) => {
        return cellValue === '1' ? '固定金额' : '比例';
      },
    },
    {
      title: '安全率/安全金额',
      required: true,
      align: 'center',
      key: 'safetyRate',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '商品条形码',
      align: 'center',
      key: 'barcode',
      type: 'input',
      width: 160
    },
    {
      title: '最小起售量',
      required: true,
      align: 'center',
      key: 'saleMin',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '销售限制类型',
      required: true,
      key: 'saleRestrict',
      align: 'center',
      type: 'select',
      options: saleRestrictOptions,
      width: 160
    },
    {
      title: '商品信息备注',
      key: 'skuRemark',
      type: 'inputHasMaxLength',
      width: 160,
      maxlength: 500
    },
    {
      title: '包装清单',
      required: true,
      key: 'packageContents',
      type: 'inputHasMaxLength',
      width: 160,
      maxlength: 200
    },
    {
      title: '产地',
      required: true,
      width: 160,
      render: (h, { row, index }) => {
        return (
          <el-input
            prefix-icon="el-icon-search"
            readonly
            value={ row.producingAreaName }
            onFocus={ () => { handleChooseOriginalPlace({ index }) } }
          />
        )
      }
    },
    {
      title: 'Sku来源',
      required: true,
      key: 'skuSource',
      width: 160,
      type: 'select',
      options: skuOriginalOptions,
    },
    {
      title: '来源详情',
      key: 'skuSourceDesc',
      type: 'input',
      width: 160
    },
    {
      title: '件装数量',
      required: true,
      align: 'center',
      key: 'pieceInfo',
      type: 'input',
      width: 160
    },
    {
      title: '层数',
      required: true,
      key: 'packageLayers',
      align: 'center',
      type: 'select',
      options: packageLayersOptions,
      width: 160
    },
    {
      title: '单品包装单位',
      required: true,
      key: 'singlePackageUnit',
      align: 'center'
    },
    {
      title: '单品数量',
      required: true,
      align: 'center',
      key: 'singlePackageCount',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '单品最长边(cm)',
      required: true,
      align: 'center',
      key: 'singleEdge1',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '单品次长边(cm)',
      required: true,
      align: 'center',
      key: 'singleEdge2',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '单品最短边(cm)',
      required: true,
      align: 'center',
      key: 'singleEdge3',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '单品体积(m³)',
      required: true,
      align: 'center',
      key: 'singleVolume',
    },
    {
      title: '单品重量(kg)',
      required: true,
      align: 'center',
      key: 'singleWeight',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '一层包装单位',
      align: 'center',
      key: 'onePackageUnit',
      width: 160,
      render: (h, { row, index }) => {
        return (
          <el-input
            prefix-icon="el-icon-search"
            readonly
            value={ row.onePackageUnit }
            onFocus={ () => { handleChooseMainUnit({ type: 'onePackageUnit', index }) } }
          />
        )
      }
    },
    {
      title: '一层数量',
      align: 'center',
      key: 'onePackageCount',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '一层最长边(cm)',
      align: 'center',
      key: 'oneEdge1',
      type: 'inputNumChange',
      width: 160
    }, {
      title: '一层次长边(cm)',
      align: 'center',
      key: 'oneEdge2',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '一层最短边(cm)',
      align: 'center',
      key: 'oneEdge3',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '一层体积(m³)',
      align: 'center',
      key: 'oneVolume',
    },
    {
      title: '一层重量(kg)',
      align: 'center',
      key: 'oneWeight',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '二层包装单位',
      align: 'center',
      key: 'twoPackageUnit',
      width: 160,
      render: (h, { row, index }) => {
        return (
          <el-input
            prefix-icon="el-icon-search"
            readonly
            value={ row.twoPackageUnit }
            onFocus={ () => { handleChooseMainUnit({ type: 'twoPackageUnit', index }) } }
          />
        )
      }
    },
    {
      title: '二层数量',
      align: 'center',
      key: 'twoPackageCount',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '二层最长边(cm)',
      align: 'center',
      key: 'twoEdge1',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '二层次长边(cm)',
      align: 'center',
      key: 'twoEdge2',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '二层最短边(cm)',
      align: 'center',
      key: 'twoEdge3',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '二层体积(m³)',
      align: 'center',
      key: 'twoVolume',
    },
    {
      title: '二层重量(kg)',
      align: 'center',
      key: 'twoWeight',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '三层包装单位',
      align: 'center',
      key: 'threePackageUnit',
      width: 160,
      render: (h, { row, index }) => {
        return (
          <el-input
            prefix-icon="el-icon-search"
            readonly
            value={ row.threePackageUnit }
            onFocus={ () => { handleChooseMainUnit({ type: 'threePackageUnit', index }) } }
          />
        )
      }
    },
    {
      title: '三层数量',
      align: 'center',
      key: 'threePackageCount',
      type: 'inputSpecialNum',
      width: 160
    },
    {
      title: '三层最长边(cm)',
      align: 'center',
      key: 'threeEdge1',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '三层次长边(cm)',
      align: 'center',
      key: 'threeEdge2',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '三层最短边(cm)',
      align: 'center',
      key: 'threeEdge3',
      type: 'inputNumChange',
      width: 160
    },
    {
      title: '三层体积(m³)',
      key: 'threeVolume',
      align: 'center',
    },
    {
      title: '三层重量(kg)',
      align: 'center',
      key: 'threeWeight',
      type: 'inputSpecialNum',
      width: 160
    }
  ]
  return columns
}

export const getBasicKeysFunc = (source) => {
  const basicKeyList = [
    'skuNo', // SKU编码
    'skuName', // 销售属性
    'addPriceType', // 加价类型
    'skuRemark', // 商品信息备注
    'safetyRate', // 安全率/安全金额
    'barcode', // 商品条形码
    'saleMin', // 最小起售量
    'saleRestrict', // 销售限制类型
    'packageLayers', // 包装层数
    'pieceInfo', // 件装数量
    'skuSource', // Sku来源
    'skuSourceDesc', // 来源详情
    'packageContents', // 包装清单
    'producingAreaName', // 产地名称
    'producingAreaCode', // 产地代码
  ];
  return basicKeyList.reduce((value, item) => {
    if (!source[item] && source[item] !== 0) {
      value[item] = null;
    } else {
      value[item] = source[item];
    }
    return value;
  }, {});
}
